<template>
  <view class="weather-container">
    
    <view v-if="tomorrowWeather" class="weather-card">
      <view class="title">明天天气预报</view>
      <view>日期：{{ tomorrowWeather.date }}</view>
      <view>星期：{{ tomorrowWeather.week }}</view>
      <view>最高温：{{ tomorrowWeather.high }}℃</view>
      <view>最低温：{{ tomorrowWeather.low }}℃</view>
    </view>
    <view v-else>加载中...</view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      tomorrowWeather: null // 存储明天的天气信息
    };
  },
  onLoad() {
    this.getWeather(); 
  },
  methods: {
    getWeather() {
      uni.request({
        url: 'http://t.weather.sojson.com/api/weather/city/101230501', 
        success: (res) => {
         
          const weatherData = res.data.data.forecast[1]; 
          this.tomorrowWeather = {
            date: weatherData.date,
            week: weatherData.week,
            high: weatherData.high.replace('高温 ', ''), 
            low: weatherData.low.replace('低温 ', '')    
          };
        },
        fail: (eMsg) => {
          uni.showToast({
            title: '请求失败',
            icon: 'none'
          });
          console.error('请求失败：', eMsg);
        }
      });
    }
  }
};
</script>

<style>
.weather-container {
  padding: 30rpx;
}
.weather-card {
  background: #f5f5f5;
  border-radius: 12rpx;
  padding: 20rpx;
}
.title {
  font-size: 36rpx;
  font-weight: bold;
  margin-bottom: 20rpx;
}
</style>